package com.yanyu.space.codegen.controller;


import com.yanyu.space.codegen.bean.po.TemplateGroup;
import com.yanyu.space.codegen.bean.vo.templateGroup.TemplateGroupSearchVo;
import com.yanyu.space.codegen.service.ITemplateGroupService;
import com.yanyu.space.common.core.bean.db.PageEntity;
import com.yanyu.space.common.core.bean.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模板分组 前端控制器
 * @author yanyu
 * @date 2020/12/1
 */
@RestController
@Validated
@Api(tags = "模板分组信息")
@RequestMapping("/codegen/templateGroup")
@AllArgsConstructor
public class TemplateGroupController {

    private ITemplateGroupService service;

    @GetMapping("/list")
    @ApiOperation(value = "查询模板分组信息")
    public R list(TemplateGroupSearchVo vo) {
        PageEntity<TemplateGroup> page = service.listPage(vo);
        return R.ok(page);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询模板组信息")
    public R get(@PathVariable("id") Long id) {
        TemplateGroup templateGroup = service.getById(id);
        return R.ok(templateGroup);
    }

    @PostMapping
    @ApiOperation(value = "新增模板分组")
    public R add(@RequestBody TemplateGroup vo) {
        service.add(vo);
        return R.ok();
    }

    @PutMapping
    @ApiOperation(value = "修改模板分组")
    public R update(@RequestBody TemplateGroup vo) {
        service.updateById(vo);
        return R.ok();
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除模板分组")
    public R delete(@PathVariable("ids") List<Long> ids) {
        service.removeByIds(ids);
        return R.ok();
    }
}

